using System;
using System.Threading.Tasks;
using Blog.DAL;
using Blog.Models;
using System.Linq;
using Blog.Util;

namespace Blog.BLL
{
    public class AccountBLL:IAccountBLL
    {
        private readonly BloggingContext _context;
        public AccountBLL(BloggingContext context)
        {
            _context = context;

        }

        public int Insert(Account account)
        {
            account.CreateTime = account.UpdateTime = DateTime.Now;
             _context.Accounts.Add(account);
           return _context.SaveChanges();
        }

        ///<sumarry>
        ///添加账户
        ///</sumarry>
        public async Task<int> InsertAsync(Account account)
        {
            account.CreateTime = account.UpdateTime = DateTime.Now;
            await _context.Accounts.AddAsync(account);
           return await _context.SaveChangesAsync();
        }
        public Account GetAccount(string userName,string pwd)
        {
            return  _context.Accounts.FirstOrDefault(e=>e.UserName.Equals(userName)&&e.PassWord.Equals(SecurityHelper.Encrypt(pwd)));
        }
    }
}